﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.ComponentModel;

namespace nsGumController
{
    /// <summary>
    /// 用于绑定到界面DataGridView上的数据类
    /// </summary>
    public class ActionParas
    {
        public ActionParas()
        {
            _Cmd = 0;
            _Point1X = 0;
            _Point1Y = 0;
            _Point2X = 0;
            _Point2Y = 0;
            _Radius = 0;
            _Mode = 0;
        }

        public GUM_ACTION Cmd
        {
            get { return _Cmd; }
            set { _Cmd = value; }
        }
        public int Point1X
        {
            get { return _Point1X; }
            set { _Point1X = value; }
        }
        public int Point1Y
        {
            get { return _Point1Y; }
            set { _Point1Y = value; }
        }
        public int Point2X
        {
            get { return _Point2X; }
            set { _Point2X = value; }
        }
        public int Point2Y
        {
            get { return _Point2Y; }
            set { _Point2Y = value; }
        }
        public int Radius
        {
            get { return _Radius; }
            set { _Radius = value; }
        }
        public int Mode
        {
            get { return _Mode; }
            set { _Mode = value; }
        }

        private GUM_ACTION _Cmd;
        private int _Point1X;
        private int _Point1Y;
        private int _Point2X;
        private int _Point2Y;
        private int _Radius;
        private int _Mode;
    }

    public struct ET_GPES_SENDMSG
    {
        public byte CLA;          // 模块名称
        public byte INS;          // 命令号
        //public int MsgLen;
        public byte[] sendMsg;
    };

    public struct ET_GPES_RECVMSG
    {
        public int RetLen;
        public byte RES;
        public byte[] recvMsg;
    };

    /// <summary>
    /// 下位机发送的状态数据结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct MASHINE_INFO
    {
        // 当前坐标
        public int x;
        public int y;
        public int z; 					// 后续点焊机有用

        // 原点坐标
        public int originX;
        public int originY;
        public int originZ;

        // 各部件状态 
        // 0-停止 1-正向 2-负向
        public byte statLineMotor;

        // 0-Back 1-Out
        public byte statC1;
        public byte statC2;
        public byte statC3;
        public byte statCz;

        // 0-Close 1-Open
        public byte statGumPointer;

        // 0-停止 1-正向 2-负向 3-异常
        public byte statX;
        public byte statY;
        public byte statZ;  			// 后续点焊机有用

        // 自动控制状态
        public byte iRunningFlag; 	    // 自动控制运行/停止
        public byte iPausedFlag; 	    // 自动控制暂停/恢复
        public byte iProcessingFlag; 	// 有工件正在处理

        public int currentStep;         // 指示当前自动运行到了哪一步
    };

    #region 发送给下位机的自动动作结构体
    public enum GUM_ACTION
    {
        Z轴抬起 = 0,
        Z轴压下,
        点胶开,
        点胶关,
        画直线,
        画圆弧,
        移动到,
        延时,
        //设置原点 = 0xF0
    };
    [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct ET_Coordinate
    {
        public ET_Coordinate(int _x, int _y)
        {
            x = _x;
            y = _y;
        }
        public int x;
        public int y;
    };
    [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct ET_GumAction
    {
        public int cmd;
        public ET_Coordinate tCoord1;
        public ET_Coordinate tCoord2;
        public int r;
        public int mode;
        //压下
        //抬起
        //开始点胶
        //停止点胶 	：
        //直线 		：起点、终点
        //圆弧 		：圆心、半径、mode
    };
    /// <summary>
    /// 发送给下位机的自动动作结构体
    /// </summary>
    [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
    public struct ET_GumActions
    {
        public int cnt;
        public ET_GumAction[] ptAct;
    };
    #endregion

    public enum CLA
    {
        CLA_CTRL = 0x11,
        CLA_QUERY = 0x12
    }

    public enum INS
    {
        [Description("原点设置")]
        CMD_SET_ORIGIN = 0x01,
        [Description("坐标设定")]
        CMD_MOVETO,
        [Description("坐标微调")]
        CMD_ADJUST,
        [Description("Z轴控制")]
        CMD_Cz,
        [Description("C1控制")]
        CMD_C1,
        [Description("C2控制")]
        CMD_C2,
        [Description("C3控制")]
        CMD_C3,
        [Description("点胶开关")]
        CMD_GUMPOINTER,
        [Description("线体马达控制")]
        CMD_LM,
        [Description("参数设置")]
        CMD_SET_PARAMETER,
        [Description("移到原点")]
        CMD_MOVETO_ORIGIN,
        //////////////////////////////////////////////////////////////////////////
        // 以上指令不允许在自动运行过程中发送，以下允许
        // DockSerialProtocol.cs:   if (stSend.CLA == (byte)CLA.GUM_CONTROL && stSend.INS < (byte)INS.COMMAND
        //////////////////////////////////////////////////////////////////////////
        //[Description("自动控制")]
        //CMD_AUTO_CONTROL,
        [Description("开始")]
        CMD_START,
        [Description("暂停")]
        CMD_PAUSE,
        [Description("继续")]
        CMD_RESUME,
        [Description("取消")]
        CMD_ABORD,
        [Description("停止")]
        CMD_STOP,
        [Description("复位")]
        CMD_RESET,
        [Description("点胶延时设置")]
        CMD_GUM_DELAY,
        [Description("传感器设置")]
        CMD_SENSOR = 0xF0,
        [Description("重复点胶")]
        CMD_REPEAT,
        [Description("INP设置")]
        CMD_INP,
        [Description("AtHome设置")]
        CMD_ATHOME,
        [Description("IO测试")]
        CMD_IOTEST,
        [Description("拷机测试开关")]
        CMD_LIFETEST
    }
}